package com.yx.system.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yx.common.utils.PageUtils;
import com.yx.common.utils.Query;
import com.yx.common.utils.R;
import com.yx.system.entity.TbKwordPrice;
import com.yx.system.service.TbKwordPriceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 千字付费
 * 
 * @author luo
 * @email www.baidu.com
 * @date 2018-07-24 14:09:33
 */
@RestController
@RequestMapping("sys/kwordprice")
public class TbKwordPriceController {
	@Autowired
	private TbKwordPriceService kwordPriceService;


	/*
	* 查询所有的章节定价
	*/
	@RequestMapping("findAll")
	public R findAll(){
		List<TbKwordPrice> tbKwordPrices = kwordPriceService.findAll();
		return R.ok().put("data",tbKwordPrices);
	}


	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:kwordprice:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TbKwordPrice> kwordPriceList = kwordPriceService.queryList(query);
		int total = kwordPriceService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(kwordPriceList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:kwordprice:info")
	public R info(@PathVariable("id") Integer id){
		TbKwordPrice kwordPrice = kwordPriceService.queryObject(id);
		kwordPrice.setPrice(kwordPrice.getPrice()/100);
		return R.ok().put("kwordPrice", kwordPrice);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sys:kwordprice:save")
	public R save(@RequestBody TbKwordPrice kwordPrice){
		kwordPrice.setPrice(kwordPrice.getPrice()*100);
		kwordPrice.setCreatedate(new Date());
		kwordPriceService.save(kwordPrice);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sys:kwordprice:update")
	public R update(@RequestBody TbKwordPrice kwordPrice){
		kwordPrice.setPrice(kwordPrice.getPrice()*100);
		kwordPriceService.update(kwordPrice);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sys:kwordprice:delete")
	public R delete(@RequestBody Integer[] ids){
		kwordPriceService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
